package com.miao.activity.service.impl;


import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miao.commonn.utils.PageUtils;
import com.miao.commonn.utils.Query;

import com.miao.activity.dao.OrderInfoDao;
import com.miao.activity.entity.OrderInfoEntity;
import com.miao.activity.service.OrderInfoService;


@Service("orderInfoService")
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoDao, OrderInfoEntity> implements OrderInfoService {

    @Autowired
    RedisTemplate redisTemplate;


    @Autowired
    RedissonClient redissonClient;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        RLock rlock = redissonClient.getLock("rlock");
        IPage<OrderInfoEntity> list =null;
        try {
            rlock.lock();

            BoundHashOperations orderlist = redisTemplate.boundHashOps("orderlist");

             list = (IPage<OrderInfoEntity>) orderlist.get("list");

            if (list==null){

                list = this.page(
                        new Query<OrderInfoEntity>().getPage(params),
                        new QueryWrapper<OrderInfoEntity>()
                );
                orderlist.put("list",list);

                System.out.println("未抓取");
                return new PageUtils(list);
            }
    }finally {
            rlock.unlock();
    }
            System.out.println("已抓取");
        return new PageUtils(list);
    }

}